package dxlateplate;

import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.logging.Logger;

import javax.jdo.PersistenceManager;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.google.appengine.api.users.User;
import com.google.appengine.api.users.UserService;
import com.google.appengine.api.users.UserServiceFactory;
import com.google.appengine.api.datastore.Key;
import com.google.appengine.api.datastore.KeyFactory;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;

public class DeleteLatePlateServlet extends HttpServlet {
    private static final Logger log = Logger.getLogger(DeleteLatePlateServlet.class.getName());

    public void doPost(HttpServletRequest req, HttpServletResponse resp)
                throws IOException {

    	Key plateKey;
    	String keyString = req.getParameter("plateKey");
    	if(keyString != null) {
    		plateKey = KeyFactory.stringToKey(keyString);
    	} else {
    		plateKey = KeyFactory.createKey(req.getParameter("keyKind"), Integer.parseInt(req.getParameter("keyId")));
    	}
        PersistenceManager pm = PMF.get().getPersistenceManager();
        LatePlate plate = (LatePlate) pm.getObjectById(LatePlate.class, plateKey);
        
        try {
            pm.deletePersistent(plate);
        } finally {
            pm.close();
        }

        resp.sendRedirect("/latePlateList.jsp");
    }
}